package com.example.validatestudy.demos.se;

import com.alibaba.fastjson.JSON;
import com.example.validatestudy.demos.jdk8.User;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;

public class StringTest {


    public static void main(String[] args) {
//        String url = "https://standard-file-transfer.oss-cn-hangzhou.aliyuncs.com/public/7026068418852864003/elephant/2024/08/26/172466456209976525.jpeg?response-content-type=image/jpg";
//        String url = "https://standard-file-transfer.oss-cn-hangzhou.aliyuncs.com/public/7026068418852864003/elephant/2024/08/26/172466035483824978.pdf?response-content-type=application/pdf";
//        String url = "https://standard-file-transfer.oss-cn-hangzhou.aliyuncs.com/public/7026068418852864003/elephant/2024/08/26/172466456209976525.jpeg?response-content-type=image/jpg&x-oss-process=image/crop,x_603,y_599,w_594,h_391/rotate,0";
        String url = "https://standard-file-transfer.oss-cn-hangzhou.aliyuncs.com/public/conversion/output/7026068418852864003/20240826/1827984136388767744/1.jpg?response-content-type=image/jpg&x-oss-process=image/resize,w_4096,h_4096,m_lfit/rotate,0";
        String fileName = getFileNameFromUrl(url);
        System.out.println("文件名: " + fileName);

        List list = Arrays.asList(1,2,3,4,5);
        List<User> users = Arrays.asList(new User("王"),new User("问"));
        for (int i = 0; i < list.size(); i++) {
            if(i==2){
               if(users.stream().anyMatch(item->"王".equals(item.getName()))){
                   System.out.println("忽略");
                    continue;
               }
            }
            System.out.println(i);
        }




//        BigDecimal d = new BigDecimal("1");
//        System.out.println(d.compareTo(BigDecimal.ZERO));
//
//        int n = 9;
//        List<String> result = divideIntegers(n);
//        for (String r: result) {
//            System.out.println(r);
//        }


        StringBuilder sbd = new StringBuilder();
        sbd.append("");
        sbd.toString();

        /**
         * StringBuffer 线程安全，append方法增加了synchronized修饰
         */
        StringBuffer sbf = new StringBuffer();
        sbf.append("");
        sbf.toString();

//        Map<String,Object> parametersResult = new HashMap<>();
//        parametersResult.put("result",false);
//        parametersResult.put("billType",511);
//        System.out.println(JSON.toJSONString(parametersResult));
//        List<Object> output = new ArrayList<>();
//        if(!parametersResult.isEmpty()){
//            HashMap<String,Object> parametersMap = new HashMap();
//            parametersMap.put("参数",parametersResult);
////            output.add(JSON.toJSONString(parametersMap));
//            output.add(parametersMap);
//        }
//        UruleReponseDTO dto = new UruleReponseDTO(output,1);
//        System.out.println(JSON.toJSONString(dto));



    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class UruleReponseDTO {
        private List<Object> output;

        private Integer duration;
    }

    public static List<String> divideIntegers(int n) {
        if (n <= 0) {
            throw new IllegalArgumentException("n 必须是正整数");
        }

        int[] numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        List<List<Integer>> dividedLists = new ArrayList<>();
        int numPerPart = numbers.length / n;
        int remainder = numbers.length % n;

        int start = 0;
        for (int i = 0; i < n; i++) {
            int end = start + numPerPart;
            if (remainder > 0) {
                end++;
                remainder--;
            }

            List<Integer> part = new ArrayList<>();
            for (int j = start; j < end; j++) {
                part.add(numbers[j]);
            }
            dividedLists.add(part);
            start = end;
        }

        List<String> result = new ArrayList<>();
        for (List<Integer> list : dividedLists) {
            StringBuilder sb = new StringBuilder();
            for (Integer num : list) {
                sb.append(num).append(",");
            }
            sb.deleteCharAt(sb.length() - 1);  // 去掉最后多余的逗号
            result.add(sb.toString());
        }

        return result;
    }


    public static String getFileNameFromUrl(String urlString) {
        try {
            URL url = new URL(urlString);
            String path = url.getPath();
            String[] parts = path.split("/");
            String fileName = parts[parts.length - 1];
            // 获取文件扩展名
            int dotIndex = fileName.lastIndexOf('.');
            String extension = dotIndex > 0? fileName.substring(dotIndex) : "";
            return extension;
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        }
    }
}
